package com.ibenew.demo.bcspaneldemo.weight;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ibenew.demo.bcspaneldemo.R;

/**
 * Created by jim_mac on 17/7/26.
 * 用与填写用户信息
 */

public class UserInfoView extends LinearLayout {
    private TextView mTvTitle,mTvText;
    private int DP = 0;
    public UserInfoView(Context context) {
        this(context,null);
    }

    public UserInfoView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public UserInfoView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        DP = getResources().getDimensionPixelSize(R.dimen.dp1);
        setOrientation(HORIZONTAL); //设置成横向显示
        int dp10 = 10 * DP;
        this.setPadding(dp10,dp10,dp10,dp10);
        initTextView(context);
//        this.setBackgroundColor(Color.WHITE);

    }

    private void initTextView(Context context) {
        mTvText = new TextView(context);
        mTvTitle = new TextView(context);
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.weight = 1;
        params.setMargins(5,5,5,5);
        mTvTitle.setLayoutParams(params);
        mTvText.setLayoutParams(params);
        mTvTitle.setText("Hello");
        mTvText.setText("World");
        mTvText.setTextSize(DP * 16);
        mTvTitle.setTextSize(DP * 16);
        mTvText.setBackgroundColor(getResources().getColor(R.color.userInfoTextBackground));
        mTvTitle.setBackgroundColor(getResources().getColor(R.color.userInfoTitleBackground));
        this.addView(mTvTitle);
        this.addView(mTvText);

    }



    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();

        // 将边框设为黑色.
        paint.setColor(android.graphics.Color.RED);

        // 画TextView的4个边.
        canvas.drawLine(0, 0, this.getWidth() - 1, 1, paint);
        canvas.drawLine(0, 0, 1, this.getHeight() - 1, paint);
        canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint);
        canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, paint);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
